package com.juhuixing.common.base;

import io.swagger.annotations.ApiModelProperty;

/**
 * 功能描述: 返回体包装类
 * @author: 刘猛
 * @date: 2019/5/5 15:19
 **/
public class ResponseData<T> {
	@ApiModelProperty(value = "响应code")
	private int code = 200;
	@ApiModelProperty(value = "响应消息内容")
	private String message = "";
	@ApiModelProperty(value = "响应数据")
	private T data;
	
	public static<T> ResponseData ok(T data) {
		return new ResponseData(data);
	}

	public static ResponseData ok() {
		return new ResponseData();
	}
	
	public static ResponseData fail() {
		return new ResponseData(null);
	}
	
	public static ResponseData fail(String message) {
		return new ResponseData(message);
	}
	
	public static ResponseData fail(String message, int code) {
		return new ResponseData(message, code);
	}
	
	public static ResponseData failByParam(String message) {
		return new ResponseData(message, ResponseCode.PARAM_ERROR_CODE.getCode());
	}
	
	public ResponseData(T data) {
		super();
		this.data = data;
	}
	
	public ResponseData(String message) {
		super();
		this.message = message;
	}
	
	public ResponseData(String message, int code) {
		super();
		this.message = message;
		this.code = code;
	}
	
	public ResponseData() {
		super();
	}
	
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	
}
